/**
 * 
 */
package TelitPy;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

/**
 * Classe responsavel pelo controle do periodo de <i>time-out</i> da comunicacao.
 * Os metodos <code>start()</code> e <code>stop()</code> so sao utilizados nas
 * classes Receiver.java e Sender.java.
 * 
 * @author Emerson Beserra
 *
 */
public class TimeOut implements ActionListener
{

	private volatile Timer timer;
	
	public TimeOut()
	{
		timer = new Timer(3000, this);
	}
	
	public TimeOut(int ms)
	{
		timer = new Timer(ms, this);
	}
	
	public synchronized void start()
	{
		timer.start();
	}
	
	public synchronized void stop()
	{
		timer.stop();
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == timer)
		{
			//TODO: lancar mensagem de erro por time-out
			System.out.println("TIME-OUT");
			timer.stop();
		}//end timer
	}

}
